package cs2340.spring13.team3.wheresmystuff.views;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import cs2340.spring13.team3.wheresmystuff.R;
import cs2340.spring13.team3.wheresmystuff.model.Item;
import cs2340.spring13.team3.wheresmystuff.model.User;
import cs2340.spring13.team3.wheresmystuff.presenters.LoginManager;

/**
 * This class shows a list of all the items that the user has lost.
 * 
 * @author carmen78xy
 * @version 0.1
 */
public class ViewLostItemsActivity extends Activity {

	private User currentUser;
	private List<String> lostItemNames;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_view_lost_items);
		ListView lv = (ListView) findViewById(R.id.lostItemList);

		currentUser = LoginManager.getInstance().getUser();
		System.out.println("my name in view lost:" + currentUser.getName());
		List<Item> lostItems = currentUser.getItems();
		lostItemNames = new ArrayList<String>();

		for (Item item : lostItems) {
			lostItemNames.add(item.getName());
			System.out.println(item.getName());
		}

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, lostItemNames);
		lv.setAdapter(adapter);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.view_lost_items, menu);
		return true;
	}

	/**
	 * Starts the addItemActivity when the user clicks the "add more" button.
	 * 
	 * @param view
	 */
	public void onAddClick(View view) {
		Intent intent = new Intent(this, AddItemActivity.class);
		startActivity(intent);
	}
}
